package wat.ziszcommon.clientgui;


import java.awt.Component;
import java.awt.Font;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 *
 * @author kubaolszewski
 */

 public class MyTreeCellRenderer extends DefaultTreeCellRenderer
    {
        public MyTreeCellRenderer()
        {
            super();
        }    
        
    @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value,
                                                      boolean selection, boolean expanded,
                                                      boolean leaf, int row, boolean hasFocus)
        {
            super.getTreeCellRendererComponent(tree, value, selection, expanded, 
                                               leaf, row, hasFocus);
            
            DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
            
            setIconAndToolTip(node.getUserObject(), tree);
            setFontAndToolTop(node.getUserObject(), tree);
            return this;
        }
        
        private void setFontAndToolTop(Object obj, JTree tree){
            
            if(obj instanceof MyJPanel){
                MyJPanel myPanel = (MyJPanel)(obj);
                if(myPanel.isBold()){
                   Font font = new Font("Tahoma", Font.BOLD, 12);
                   this.setFont(font);
                }else{
                   Font font = new Font("Tahoma", Font.PLAIN, 11);
                   this.setFont(font);
                }
            }else{
                Font font = new Font("Tahoma", Font.PLAIN, 11);
                this.setFont(font);
            }
        }
        
        
        private void setIconAndToolTip(Object obj, JTree tree)
        {
            if(obj instanceof MyJPanel){
               MyJPanel myPanel = (MyJPanel)(obj);
               if(myPanel.getImageIcon() != null){
                   setIcon(myPanel.getImageIcon());
               }
            }
        }
    }     